﻿namespace WMS6.Web
{
    using System;
    using System.Collections.Generic;
    using System.Data;
    using System.Web;
    using WMS6.Web.InvMovementServiceRef;

    public class InvMovementServiceClientProxy : BasePage
    {
        public string AllocateMovement(string movementID)
        {
            PubParasInfo pubParasInfo = this.InitPubParasInfo();
            using (InvMovementServiceClient client = new InvMovementServiceClient("WSHttpBinding_IInvMovementService"))
            {
                return client.AllocateMovement(movementID, pubParasInfo);
            }
        }

        public string DeleteMovement(List<string> IDS)
        {
            PubParasInfo pubParasInfo = this.InitPubParasInfo();
            using (InvMovementServiceClient client = new InvMovementServiceClient("WSHttpBinding_IInvMovementService"))
            {
                return client.DeleteMovement(IDS, pubParasInfo);
            }
        }

        public string DeleteMovementDetail(string movementID, List<string> LineID)
        {
            PubParasInfo pubParasInfo = this.InitPubParasInfo();
            using (InvMovementServiceClient client = new InvMovementServiceClient("WSHttpBinding_IInvMovementService"))
            {
                return client.DeleteMovementDetail(movementID, LineID, pubParasInfo);
            }
        }

        public MovementDetailInfo GetAllMovementDetailByID(string movementID, string lineId)
        {
            PubParasInfo pubParasInfo = this.InitPubParasInfo();
            using (InvMovementServiceClient client = new InvMovementServiceClient("WSHttpBinding_IInvMovementService"))
            {
                return client.GetAllMovementDetailByID(movementID, lineId, pubParasInfo);
            }
        }

        public static InvMovementServiceClientProxy GetInstance()
        {
            return new InvMovementServiceClientProxy();
        }

        public DataSet GetMovementAllInfo()
        {
            PubParasInfo pubParasInfo = this.InitPubParasInfo();
            using (InvMovementServiceClient client = new InvMovementServiceClient("WSHttpBinding_IInvMovementService"))
            {
                return client.GetMovementAllInfo(pubParasInfo);
            }
        }

        public MovementInfo GetMovementInfoByID(string transID)
        {
            PubParasInfo pubParasInfo = this.InitPubParasInfo();
            using (InvMovementServiceClient client = new InvMovementServiceClient("WSHttpBinding_IInvMovementService"))
            {
                return client.GetMovementInfoByID(transID, pubParasInfo);
            }
        }

        public DataSet GetMovementInfoByQueryEntity(MovementQueryEntity movementQueryEntity)
        {
            PubParasInfo pubParasInfo = this.InitPubParasInfo();
            using (InvMovementServiceClient client = new InvMovementServiceClient("WSHttpBinding_IInvMovementService"))
            {
                return client.GetMovementInfoByQueryEntity(movementQueryEntity, pubParasInfo);
            }
        }

        private PubParasInfo InitPubParasInfo()
        {
            if (base.UserInfo != null)
            {
                return new PubParasInfo { UserID = base.UserInfo.UserID, UserLanguage = base.UserInfo.Preference.Lang, CurrentWH = base.UserInfo.CurrentWH };
            }
            HttpContext.Current.Response.Redirect("../Login.aspx?from=Logout", true);
            return null;
        }

        public string InsertMovement(MovementInfo obj)
        {
            PubParasInfo pubParasInfo = this.InitPubParasInfo();
            using (InvMovementServiceClient client = new InvMovementServiceClient("WSHttpBinding_IInvMovementService"))
            {
                return client.InsertMovement(obj, pubParasInfo);
            }
        }

        public string InsertMovementDetail(MovementDetailInfo obj)
        {
            PubParasInfo pubParasInfo = this.InitPubParasInfo();
            using (InvMovementServiceClient client = new InvMovementServiceClient("WSHttpBinding_IInvMovementService"))
            {
                return client.InsertMovementDetail(obj, pubParasInfo);
            }
        }

        public string MovementConfirm(string movementID)
        {
            PubParasInfo pubParasInfo = this.InitPubParasInfo();
            using (InvMovementServiceClient client = new InvMovementServiceClient("WSHttpBinding_IInvMovementService"))
            {
                return client.MovementConfirm(movementID, pubParasInfo);
            }
        }

        public string RevertAllocateMovement(string movementID)
        {
            PubParasInfo pubParasInfo = this.InitPubParasInfo();
            using (InvMovementServiceClient client = new InvMovementServiceClient("WSHttpBinding_IInvMovementService"))
            {
                return client.RevertAllocateMovement(movementID, pubParasInfo);
            }
        }

        public string UpdateMovement(MovementInfo obj)
        {
            PubParasInfo pubParasInfo = this.InitPubParasInfo();
            using (InvMovementServiceClient client = new InvMovementServiceClient("WSHttpBinding_IInvMovementService"))
            {
                return client.UpdateMovement(obj, pubParasInfo);
            }
        }

        public string UpdateMovementDetail(MovementDetailInfo obj)
        {
            PubParasInfo pubParasInfo = this.InitPubParasInfo();
            using (InvMovementServiceClient client = new InvMovementServiceClient("WSHttpBinding_IInvMovementService"))
            {
                return client.UpdateMovementDetail(obj, pubParasInfo);
            }
        }
    }
}

